1167D - Bicolored RBS - CodeForces Solution


constructive algorithms greedy *1500

Please click on ads to support us..

C++ Code:

/*
Problem: 1167D
Date: 15-02-2024 07:22 AM
*/


#include <iostream>
#include <stack>

using namespace std;

int n;
string str;
stack<bool> s;

int main() {
	cin >> n >> str;
	for(int i = 0; i < n; i++) {
		if(str[i] == '(') {
			if(s.empty()) {
				s.push(false);
				cout << 0;
			}else {
				s.push(!s.top());
				cout << s.top();
			}
		}else {
			cout << s.top();
			s.pop();
		}
	}
	cout << endl;
}


Comments

Submit
0 Comments
More Questions

1183B - Equalize Prices
1481A - Space Navigation
1437B - Reverse Binary Strings
1362B - Johnny and His Hobbies
1299A - Anu Has a Function
1111A - Superhero Transformation
954A - Diagonal Walking
39F - Pacifist frogs
1451C - String Equality
386A - Second-Price Auction
1690E - Price Maximization
282B - Painting Eggs
440A - Forgotten Episode
233B - Non-square Equation
628B - New Skateboard
262B - Roma and Changing Signs
755C - PolandBall and Forest
456B - Fedya and Maths
376B - IOU
1623B - Game on Ranges
1118A - Water Buying
1462C - Unique Number
301A - Yaroslav and Sequence
38A - Army
38C - Blinds
1197A - DIY Wooden Ladder
1717D - Madoka and The Corruption Scheme
1296D - Fight with Monsters
729D - Sea Battle
788A - Functions again